#include <stdio.h>
#include <time.h>

int main() {

    time_t tm = time(NULL);

    printf("当前时间戳为：%ld\n", tm);

    //1 第一种方法 获取本地时间 字符串
    char *cTime = ctime(&tm);
    printf("当前时间（字符串）为：%s", cTime);

    //2 第二种方法 获取世界时间 
    //struct tm *gmtime(const time_t *timep);
    struct tm *gTime = gmtime(&tm);
    
    printf("date: %d/%d/%d\n",
                        (1900+gTime->tm_year),
                        (1+gTime->tm_mon),
                        gTime->tm_mday);
    
    printf("time:%d:%d:%d\n",
                        gTime->tm_hour,
                        gTime->tm_min,
                        gTime->tm_sec);
    //3 第三种方法 获取本地时间
    //struct tm *localtime(const time_t *timep);
    struct tm *lTime = localtime(&tm);

    printf("date:%d:%d:%d\n",
                    (1900+lTime->tm_year),
                    (1+lTime->tm_mon),
                    lTime->tm_mday);

    printf("time:%d:%d:%d\n",
                    lTime->tm_hour,
                    lTime->tm_min,
                    lTime->tm_sec);
    
}